#!/usr/bin/php
<?php

if (php_sapi_name() !== "cli") exit;

require __DIR__ . "/vendor/autoload.php";

use Rudra\Cli\Console;
use App\Ship\ShipController;
use Symfony\Component\Yaml\Yaml;
use Rudra\Container\Facades\Rudra;
use Rudra\Cli\ConsoleFacade as Cli;

parse_str(implode('&', array_slice($argv, 1)), $inputArgs);

Rudra::config(Yaml::parseFile("config/setting.local.yml"));
Rudra::config()->set(require_once "app/Ship/Services.php");
Rudra::binding(Rudra::config()->get("contracts"));
Rudra::services(Rudra::config()->get("services"));
Rudra::set([Console::class, Console::class]);

(new ShipController(Rudra::run()))->eventRegistration();

foreach (Yaml::parseFile("config/commands.yml") as $name => $command) {
    Cli::addCommand($name, $command);
}

Cli::invoke($inputArgs);
